import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { IPSAppView } from '../../app/view/ipsapp-view';
import { PSAjaxControlContainerImpl } from '../psajax-control-container-impl';
import { IPSDEDRCtrl } from './ipsdedrctrl';
import { IPSDEDRCtrlItem } from './ipsdedrctrl-item';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { IPSSysImage } from '../../res/ipssys-image';

export class PSDEDRCtrlImpl extends PSAjaxControlContainerImpl implements IPSDEDRCtrl {
  get codeName(): string {
    return this.M.codeName;
  }

  protected edititemcappslanguageres: IPSLanguageRes | null = null;

  getEditItemCapPSLanguageRes(): IPSLanguageRes | null {
    if (this.edititemcappslanguageres != null) return this.edititemcappslanguageres;
    const value = this.M.getEditItemCapPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.edititemcappslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getEditItemCapPSLanguageRes') as IPSLanguageRes;
    return this.edititemcappslanguageres;
  }

  get editItemCapPSLanguageRes(): IPSLanguageRes | null {
    return this.getEditItemCapPSLanguageRes();
  }

  getEditItemCapPSLanguageResMust(): IPSLanguageRes {
    const value = this.getEditItemCapPSLanguageRes();
    if (value == null) {
      throw new Error('未指定编辑项标题语言资源');
    }
    return value;
  }

  get editItemCaption(): string {
    return this.M.editItemCaption;
  }

  protected edititempssysimage: IPSSysImage | null = null;

  getEditItemPSSysImage(): IPSSysImage | null {
    if (this.edititempssysimage != null) return this.edititempssysimage;
    const value = this.M.getEditItemPSSysImage;
    if (value == null) {
      return null;
    }
    this.edititempssysimage = this.getPSModel4('res.IPSSysImage', value, 'getEditItemPSSysImage') as IPSSysImage;
    return this.edititempssysimage;
  }

  get editItemPSSysImage(): IPSSysImage | null {
    return this.getEditItemPSSysImage();
  }

  getEditItemPSSysImageMust(): IPSSysImage {
    const value = this.getEditItemPSSysImage();
    if (value == null) {
      throw new Error('未指定编辑项图标');
    }
    return value;
  }

  protected formpsappview: IPSAppView | null = null;

  getFormPSAppView(): IPSAppView | null {
    if (this.formpsappview != null) return this.formpsappview;
    const value = this.M.getFormPSAppView;
    if (value == null) {
      return null;
    }
    this.formpsappview = this.getPSModel4('app.view.IPSAppView', value, 'getFormPSAppView') as IPSAppView;
    return this.formpsappview;
  }

  get formPSAppView(): IPSAppView | null {
    return this.getFormPSAppView();
  }

  getFormPSAppViewMust(): IPSAppView {
    const value = this.getFormPSAppView();
    if (value == null) {
      throw new Error('未指定表单视图对象');
    }
    return value;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.getPSModel4('app.control.IPSAppCounterRef', value, 'getPSAppCounterRef') as IPSAppCounterRef;
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected psdedrctrlitems: IPSDEDRCtrlItem[] | null = null;

  getPSDEDRCtrlItems(): IPSDEDRCtrlItem[] | null {
    if (this.psdedrctrlitems == null) {
      this.psdedrctrlitems = this.fillChildListModel(this.M.getPSDEDRCtrlItems, 'control.drctrl.IPSDEDRCtrlItem') as IPSDEDRCtrlItem[];
    }
    return this.psdedrctrlitems;
  }

  get psDEDRCtrlItems(): IPSDEDRCtrlItem[] | null {
    return this.getPSDEDRCtrlItems();
  }

  findPSDEDRCtrlItem(objKey: any): IPSDEDRCtrlItem | null {
    return this.getPSModel5('control.drctrl.IPSDEDRCtrlItem', this.getPSDEDRCtrlItems(), objKey) as IPSDEDRCtrlItem;
  }

  get uniqueTag(): string {
    return this.M.uniqueTag;
  }

  get hideEditItem(): boolean {
    return this.M.hideEditItem != null ? this.M.hideEditItem : false;
  }

  get cls(): string {
    return 'PSDEDRCtrlImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.drctrl.IPSDEDRCtrl' || cls == 'control.drctrl.IPSDRCtrl') return true;
    return super.instanceof(cls);
  }
}
